<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>积分兑换</title>
		<link rel="stylesheet" type="text/css" href="../css/aui.css" />
		<link rel="stylesheet" type="text/css" href="../css/style.css" />
		<link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
	</head>

	<body>

		<div class="myui-jifen-box">

			<div class="myui-jifen-1">
				<h2 id="sign"></h2>当前吾爱金币
			</div>
			<div id="bili2" class="myui-jifen-2" style="padding-top:2.5rem;">

			</div>

			<div class="auixj aui-bar aui-bar-btn" style="width:90%;" type="count" id="demo2">
				<div class="aui-bar-btn-item aui-font-size-20">
					<i class="aui-iconfont aui-icon-minus"></i>
				</div>
				<div class="auixj-quy aui-bar-btn-item">
					<input type="number" style="height: 1.8rem;font-size: 20px;" class="auinbr aui-input aui-text-center" id="count" value="10" min="10">
				</div>
				<div class="aui-bar-btn-item aui-font-size-20">
					<i class="aui-iconfont aui-icon-plus"></i>
				</div>
			</div>

			<div class="myui-jifen-bt" style="width:90%;margin: 0 auto;padding-top:.5rem;height: auto;overflow: hidden;">
				<!--
				<div style="float: left;font-size:0.7rem;display: inline-block;padding: 8px 22px;color: white;border: 1px solid;border-radius: 3px;background-color:#89AE00;" tapmode onclick="openWin('share_win')">获取金币</div>
				
				<div style="float: right;font-size:0.7rem;display: inline-block;padding: 8px 22px;color: white;border: 1px solid;border-radius: 3px;background-color:#03a9f4;" tapmode onclick="dhxj()">兑换现金</div>
				-->
			</div>
			<b style="font-size: 0.5rem;color:#f00;">↓ 支付宝收款码 ↓</b>
			<br>
			<b style="font-size: 0.5rem;color: #f00;">点击图片上传</b>

			<div id="zfb_img" style="text-align:center;padding-top:0rem;position: relative;">
				<img id="skm_img" src="../image/skm.png" alt="收款码" style="width:90%;display:inline-block;border-radius:5px;margin-top: .5rem;">
				<form enctype="multipart/form-data" style="position: absolute;width: 100%;height: 100%;left:0px;top:0px;">
					<!--贴图库Token-->
					<input name="Token" type="hidden" id="Token" value="55db290787786fca3916701082583d13f8e6f4b4:leT7VVlBypxaq7LaVNMG-Ulz1TI=:eyJkZWFkbGluZSI6MTQ5NTU5MTQ1NywiYWN0aW9uIjoiZ2V0IiwidWlkIjoiMTk0OSIsImFpZCI6IjM0OTAiLCJmcm9tIjoiZmlsZSJ9" />
					<div class="myui-jifen-bt" style="position: absolute;width: 100%;height: 100%;left:0px;top:0px;padding-top:.5rem;">
						<input onchange="changImg(event,'skm_img')" name="file" type="file" id="file" style="position: absolute;width: 100%;height: 100%;left: 0px;opacity:0;background: #0075F0;" />
						<!--<div style="font-size:0.7rem;display: inline-block;padding: 8px 22px;color: white;border: 1px solid;border-radius: 3px;background-color:#89AE00;position: relative;">
							<span>点击上传</span>
						</div> 
						<div style="font-size:0.7rem;display: inline-block;padding: 8px 22px;color: white;border: 1px solid;border-radius: 3px;background-color:#03a9f4;position: relative;">
							<input type="button" value="Upload" style="position: absolute;width: 100%;height: 100%;left: 0px;opacity:0;"/>
							<span>确认提交</span>
						</div>-->
					</div>
				</form>
			</div>

			<div class="myui-jifen-bt">
			</div>

		</div>

		<progress style="display:none"></progress>
		<div id="res"></div>

	</body>

	<script type="text/javascript" src="../script/api.js"></script>
	<script type="text/javascript" src="../script/auitab.js"></script>
	<script type="text/javascript" src="../script/jquery-3.1.1.min.js"></script>
	<script type="text/javascript" src="http://common.jb51.net/jslib/jquery/jquery.min.js"></script>
	<script>
		$(function() {
			if(localStorage.zfbImg != "" && localStorage.zfbImg != 'undefind') {
				$("#skm_img").attr("src", localStorage.zfbImg);
			}
		});
		$(':button').click(function() {

		});

		function progressHandlingFunction(e) {
			if(e.lengthComputable) {
				$('progress').attr({
					value: e.loaded,
					max: e.total
				});
			}
		}

		function changImg(e, imgid) {

			for(var i = 0; i < e.target.files.length; i++) {
				var file = e.target.files.item(i);
				if(!(/^image\/.*$/i.test(file.type))) {
					continue; //不是图片 就跳出这一次循环
				}
				//实例化FileReader API
				var freader = new FileReader();
				freader.readAsDataURL(file);
				freader.onload = function(e) {
					$("#" + imgid).attr("src", e.target.result);

					api.showProgress({
						title: '收款码上传中...',
						modal: false
					});
					var formData = new FormData($('form')[0]);
					$.ajax({
						url: 'http://up.imgapi.com/',
						type: 'POST',
						xhr: function() {
							myXhr = $.ajaxSettings.xhr();
							if(myXhr.upload) {
								myXhr.upload.addEventListener('progress', progressHandlingFunction, false);
							}
							return myXhr;
						},
						beforeSend: function() {
							//$('progress').show();

						},
						success: function(data) {
							console.log(data);
							//$('#res').html(JSON.stringify(data));
							//alert("上传成功，linkurl:" + data.linkurl);
							//window.location.reload();
							//$("#skm_img").attr("src",data.linkurl);
							var values = {
								uid: localStorage.getItem('user_id'),
								zfb: data.linkurl
							}
							//alert( JSON.stringify( values ) );
							api.ajax({
								url: 'https://test.msapp.co/login/login/zfbcz.html',
								method: 'post',
								data: {
									"values": values
								}
							}, function(ret, err) {
								if(ret) {
									//alert( JSON.stringify( ret ) );
									if(ret.code == 1) {
										api.hideProgress();
										alert('上传成功');
										localStorage.zfbImg = data.linkurl;
									} else if(ret.code == 0) {
										api.hideProgress();
										alert('修改失败');
									} else {
										api.hideProgress();
										alert('网络错误！11');
									}
								}
							});
						},
						error: function(data) {
							console.log(data);
							alert('上传失败,请稍后再试');
						},
						data: formData,
						cache: false,
						contentType: false,
						processData: false
					});

				}
			}
		}
	</script>

	<script type="text/javascript">
		var api_url = localStorage.getItem('api_url');

		apiready = function() {
			api.parseTapmode();
			api.showProgress({
				title: '正在刷新',
				text: '请稍等...',
				modal: false
			});
			api.ajax({
				url: 'https://test.msapp.co/login/login/sign.html',
				method: 'get',
				data: {
					values: {
						uid: localStorage.getItem('user_id')
					}
				}
			}, function(ret, err) {
				if(ret) {
					var sign = $api.byId('sign');
					sign.innerHTML = ret.msg['share'];
					localStorage.setItem('user_jinb', ret.msg['share']);
				} else {
					api.hideProgress();
					alert('网络错误11');
				}
			});

			api.ajax({
				url: 'https://test.msapp.co/login/login/share.html',
				method: 'get',
				data: {
					values: {
						uid: localStorage.getItem('user_id')
					}
				}
			}, function(ret, err) {
				if(ret) {
					//var bili = $api.byId('bili');

					//bili.innerHTML = '100吾爱金币可以兑换1天会员资格！';
					bili2.innerHTML = '100吾爱金币可以兑换1元现金!';
					api.hideProgress();
				} else {
					api.hideProgress();
					alert('获取失败');

				}
			});
		}

		function fasong() {
			var ajax = new XMLHttpRequest();
			ajax.open('post', 'https://test.msapp.co/appx/cesaj.php');
			ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

			var bianl1 = document.querySelector('#sign');
			var bianl2 = document.querySelector('#count').value;
			var bianl3 = Number(bianl1.innerText) - (Number(bianl2) * 100); //兑换吾爱金币/积分比率!!!!
			var bianyu = Number(bianl3);
			if(bianyu <= 0) {
				alert('吾爱金币不足，无法兑换')
				return;
			}
			var shuji = Number(bianl2);
			sign.innerHTML = bianyu;
			localStorage.setItem('user_jinb', bianyu);
			var userid = localStorage.getItem('user_id');
			var student = new Object();
			student.id = userid;
			student.age = shuji;
			var json = JSON.stringify(student);
			ajax.send('json=' + json);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4 && ajax.status == 200) {
					console.log(ajax.responseText);
					alert('兑换成功！恭喜获得' + ajax.responseText + '天VIP')
				}
			};
		}

		function dhxj() {
			var ajax = new XMLHttpRequest();
			ajax.open('post', 'https://test.msapp.co/appx/dhxj.php');
			ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

			var bianl1 = document.querySelector('#sign');
			var bianl2 = document.querySelector('#count').value;
			var bianl3 = Number(bianl1.innerText) - (Number(bianl2) * 100); //兑换吾爱金币/积分比率!!!!
			var bianyu = Number(bianl3);
			
			if(bianyu <= 0) {
				alert('吾爱金币不足，无法兑换')
				return;
			}
			if(bianl2 < 20) {
				alert('金额满50元，方可提现，或者您可以用金币兑换您的吾爱演示VIP时长哦！继续努力邀请好友吧！')
				return;
			}
			var shuji = Number(bianl2);
			localStorage.setItem('user_jinb', bianyu);
			var userid = localStorage.getItem('user_id');
			var student = new Object();
			student.id = userid;
			student.age = shuji;
			var json = JSON.stringify(student);
			//alert(json)
			ajax.send('json=' + json);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4 && ajax.status == 200) {
					if(ajax.responseText == 403) {
						alert("有未审核订单,请稍后申请提现！");
					} else {
						alert('申请提现成功！恭喜获得' + ajax.responseText + '元现金,请等待客服审核！')
						sign.innerHTML = bianyu;
					}
				}else{
					alert('网络异常请稍后再试！')
				}
			};
		}
		/*
		  function exchange00(){
		    var share = $api.val($api.byId('count'));

		    api.ajax({
		        url: api_url+'/login/login/exchange.html',
		        method: 'get',
		        data: {
		            values: {
		                uid: localStorage.getItem('user_id'),
		                share:share*jifenbi
		            }
		        }
		    },function(ret, err){
		        if (ret) {
		            if (ret.code == 0) {
		              alert( ret.msg );
		            }else {
		              getTime();
		              alert( '成功兑换'+share+'天会员' );
		            }

		        } else {
		          api.hideProgress();
		            alert( '网络错误22' );
		        }
		    });
		  }
		*/

		//重新获取到期时间
		function getTime() {
			api.ajax({
				url: 'https://test.msapp.co/login/login/veifys.html',
				method: 'get',
				data: {
					values: {
						username: localStorage.getItem('user_name'),
						passwd: localStorage.getItem('password'),
						imei: api.deviceId
					}
				}
			}, function(ret, err) {
				if(ret) {
					if(ret.code == 0) {
						api.hideProgress();
						alert('不明错误 请重新登录');
					} else if(ret.code == 1) {
						localStorage.setItem('user_time', ret.msg['time']);
						api.sendEvent({
							name: 'newLoingdata',
							extra: {}
						});
					}
				} else {
					api.hideProgress();
					alert('网络错误！33');
				}
			});
		}

		var bar = document.querySelectorAll(".aui-bar-btn");
		if(bar) {
			for(var i = 0; i < bar.length; i++) {
				var d = bar[i];
				var tab = new auiTab({
					element: bar[i],
					repeatClick: true
				}, function(ret) {
					//alert( JSON.stringify( ret ) );
					if(ret.dom.parentNode.getAttribute("type") && ret.dom.parentNode.getAttribute("type") == "count") {
						var count = parseInt(document.getElementById("count").value);
						//if(ret.index==2)return;
						if(ret.index == 1) {
							if(document.getElementById("count").value <= 1) {
								return;
							}
							document.getElementById("count").value = count - 1;
						}
						if(ret.index == 3) {
							document.getElementById("count").value = count + 1;
						}
					}
				});

			}
		}

		function openWin(name) {
			var delay = 0;
			if(api.systemType != 'ios') {
				delay = 300;
			}
			api.openWin({
				name: '' + name + '',
				url: '' + name + '.html',
				bounces: false,
				delay: delay,
				slidBackEnabled: true,
				vScrollBarEnabled: false
			});
		}
	</script>

</html>